const {verify} = require('../util/jwt')
const {jwtSecret} = require('../config')

module.exports = async (req,res,next)=>{
    let token = req.headers.token
    !token && res.status(400).end()
    !req.session.user._id && res.status(400).end()
    try{
        const decodedToken = await verify(token,jwtSecret)
        console.log(decodedToken);
        next()
    }catch(error){
        return res.status(401).end()
    }
}